package subject_set.weekly_competition.day10_15;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author haomin
 * @date 2022/10/15 22:21
 **/
public class Num2 {
    class Solution {
        public int[] productQueries(int n, int[][] queries) {
            List<Integer> list = new ArrayList<>();
            while(n != 0){
                int i = 1;
                while(i <= n) i *= 2;
                i /= 2;
                list.add(i);
                n -= i;
            }
            int[] powers = list.stream().mapToInt(Integer::intValue).toArray();
            Arrays.sort(powers);
            int[] res = new int[queries.length];
            for(int i = 0; i < queries.length; ++i){
                int[] ret = queries[i];
                long mul = 1;
                for(int j = ret[0]; j <= ret[1]; ++j){
                    mul *= powers[j];
                    mul %= 1000000007;
                }
                res[i] = (int)mul;
            }
            return res;
        }
    }
}